import axios from '../utils/request';

const BASE_URL = '/tracking';

const trackingAPI = {
  // 网站管理
  getWebsites: () => axios.get(`${BASE_URL}/websites`),
  getWebsite: (id: string | number) => axios.get(`${BASE_URL}/websites/${id}`),
  createWebsite: (data: any) => axios.post(`${BASE_URL}/websites`, data),
  updateWebsite: (id: string | number, data: any) => axios.patch(`${BASE_URL}/websites/${id}`, data),
  deleteWebsite: (id: string | number) => axios.delete(`${BASE_URL}/websites/${id}`),
  deleteAllWebsites: () => axios.delete(`${BASE_URL}/websites/all`),

  // 统计
  getWebsiteStats: (id: string | number, params: any = {}) => axios.get(`${BASE_URL}/websites/${id}/stats`, { params }),
  getWebsiteSummary: (id: string | number, params: any = {}) => axios.get(`${BASE_URL}/websites/${id}/summary`, { params }),

  // 嵌入代码
  getEmbedCode: (id: string | number) => axios.get(`${BASE_URL}/websites/${id}/embed-code`),

  // 日志统计
  getLogStats: (params: any = {}) => axios.get(`${BASE_URL}/logs/stats`, { params }),

  // 业务闭环
  getBusinessLoopLogs: (trackingId: string | number, date?: string) => axios.get(`${BASE_URL}/logs/business-loop/${trackingId}`, { params: date ? { date } : {} }),
  checkBusinessLoopIntegrity: (trackingId: string | number, date?: string) => axios.get(`${BASE_URL}/logs/business-loop/${trackingId}/integrity`, { params: date ? { date } : {} }),

  // IP与会话
  getIpVisits: (ip: string, params: any = {}) => axios.get(`${BASE_URL}/visits/ip/${ip}`, { params }),
  getSessionDetails: (sessionId: string) => axios.get(`${BASE_URL}/visits/session/${sessionId}`),
  // 获取网站所有访问过的IP列表
  getWebsiteIps: (id: string | number) => axios.get(`${BASE_URL}/websites/${id}/ips`),
};

export default trackingAPI;

